package com.mai4j.maiadmin.setup;

import com.mai4j.maiadmin.setup.db.*;
import com.mai4j.maiadmin.setup.gen.Gen;
import com.mai4j.maiadmin.setup.gen.GenJooq;
import com.mai4j.maiadmin.setup.project.New;
import com.mai4j.maiadmin.setup.project.Project;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import picocli.CommandLine;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Callable;

/**
 * Created by 席有芳 on 2023/03/02.
 *
 * @author 席有芳
 */
@CommandLine.Command(name = "setup-cli",
        version = {
                "setup-cli v1.0.0",
                "(c) 2023 youfangxi@gmail.com",
                "Website: https://www.xiyoufang.com"
        },
        description = "初始化项目的命令行工具",
        mixinStandardHelpOptions = true)
public class SetupCliStarter implements Callable<Integer> {

    @Override
    public Integer call() {
        System.out.println("使用 -h 查看帮助信息");
        return 0;
    }

    @SneakyThrows
    public static void main(String[] args) {
        if (args == null || args.length == 0) {
            args = new String[]{"-V"};
        }
        Env.setupEnv(FileUtils.readFileToString(new File("cli.properties"), StandardCharsets.UTF_8));
        int exitCode = new CommandLine(new SetupCliStarter())
                .addSubcommand(
                        new CommandLine(new Db())
                                .addSubcommand(new Migrate())
                                .addSubcommand(new Create())
                                .addSubcommand(new Drop())
                                .addSubcommand(new Seed())
                )
                .addSubcommand(
                        new CommandLine(new Gen())
                                .addSubcommand(new GenJooq())
                )
                .addSubcommand(new CommandLine(new Project())
                        .addSubcommand(new New())
                )
                .execute(args);
        System.exit(exitCode);
    }
}
